import cv2
img=cv2.imread("puppy.jpg")
if img is not None and len (img.shape) == 3:
    print('img.shape:', img.shape)
    def show_img(title,img,delay=-1):
        cv2.imshow(title,img)
        if delay == -1:
            cv2.waitKey(1000)
        else:
            cv2.waitKey(delay)
    show_img('img',img,-1)
    if img.shape[2] == 3:
        b,g,r=cv2.split(img)
        show_img('b',b,-1)
        show_img('g',g,-1)
        show_img('r',r,-1)
        cv2.waitKey()
        cv2.waitKey()#若将此行代码删除，则会一张一张地出现图片。
    elif img.shape[2] == 4:
        b,g,r,a=cv2.split(img)
        show_img('b',b,-1)